<?php
/* @var $this EnderecoController */
/* @var $model Endereco */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'endereco-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'logradouro'); ?>
		<?php echo $form->textField($model,'logradouro',array('size'=>60,'maxlength'=>60)); ?>
		<?php echo $form->error($model,'logradouro'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'bairro'); ?>
		<?php echo $form->textField($model,'bairro',array('size'=>45,'maxlength'=>45)); ?>
		<?php echo $form->error($model,'bairro'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'numero'); ?>
		<?php echo $form->textField($model,'numero'); ?>
		<?php echo $form->error($model,'numero'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'cep'); ?>
		<?php echo $form->textField($model,'cep',array('size'=>8,'maxlength'=>8)); ?>
		<?php echo $form->error($model,'cep'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'complemento'); ?>
		<?php echo $form->textField($model,'complemento',array('size'=>60,'maxlength'=>60)); ?>
		<?php echo $form->error($model,'complemento'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'cidadeEstrangeira'); ?>
		<?php echo $form->textField($model,'cidadeEstrangeira',array('size'=>60,'maxlength'=>60)); ?>
		<?php echo $form->error($model,'cidadeEstrangeira'); ?>
	</div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'pais_id'); ?>
		<?php 
			$pais = Pais::model()->findAll();
			echo $form->dropDownList($model, 'pais_id', CHtml::listData($pais, 'id', 'pais')); 
		?>
		<?php echo $form->error($model,'pais_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'uf_id'); ?>
		<?php 
			$uf = Uf::model()->findAll();
			echo $form->dropDownList($model, 'uf_id', CHtml::listData($uf, 'id', 'nome'), array(
				'ajax' => array(
					'type' => 'POST',
					'url' => CController::createUrl('endereco/dynamicUf'),
					'update' => '#Endereco_cidade_id'
				)
			)); 
		?>
		<?php echo $form->error($model,'uf_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'cidade_id'); ?>
		<?php 
		
			if(!$model->isNewRecord)
			{
				$cidade = Cidade::model()->findAll('uf_id=:uf_id', array(':uf_id' => $model->uf_id));
				echo $form->dropDownList($model, 'cidade_id', CHtml::listData($cidade, 'id', 'nome'));
			}
			else
				echo $form->dropDownList($model,'cidade_id', array()); 
		?>
		<?php echo $form->error($model,'cidade_id'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->